import 'package:flutter/material.dart';
import 'package:gold/base/config.dart';
import 'package:gold/http/api_gold.dart';
import 'package:gold/http/http.dart';
import 'package:gold/model/gold_recover_order_model.dart';
import 'package:gold/route/routes.dart';
import 'package:gold/route/xfg_nav.dart';
import 'package:gold/utils/res.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_extension.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';

/// @description: 黄金回收成功
/// @author tangzhentao
/// @created at 11:52 2024/12/15

class RecoverSuccessPage extends StatelessWidget {
  /// 订单类型
  final String type;
  /// 订单id
  final int? id;

  const RecoverSuccessPage({super.key, required this.type, this.id});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: xfgAppbar(title: '预约成功'),
      body: Column(
        children: [
          SizedBox(height: XfgSize().size128, width: XfgSize().screenWidth),
          Image.asset(Res.imagesWithdrawalSuccess, width: XfgSize().size60, height:  XfgSize().size60),
          SizedBox(height: XfgSize().size34),
          XfgText('预约成功', fontSize: XfgSize().text18, color: XfgColor.text1D),
          SizedBox(height: XfgSize().size16),
          XfgText('可以在个人中心“回收订单中”查看', fontSize: XfgSize().text14, color: XfgColor.colorB5),
          SizedBox(height: XfgSize().size97),
          TextButton(
              onPressed: () async {
                final result = await Http().request<GoldRecoverOrderModel>(ApiGold.recycleDetail, data: {'id': id}, loadingText: '加载中...');
                if (result.success) {
                  if (result.data != null) {
                    XfgNav.pushReplacementNamed(type == RecoverType.online ? Routes.myOrderRecoverOnlineDetail:Routes.myOrderRecoverOfflineDetail, arguments: result.data);
                  } else {
                    '订单信息异常'.toast();
                  }
                }
              },
              style: xfgButtonStyle(Size(XfgSize().size200, XfgSize().size50), radius: XfgSize().size50),
              child: XfgText('查看订单', fontSize: XfgSize().text18, color: XfgColor.white, bold: FontWeight.bold)
          ),
          SizedBox(height: XfgSize().size20),
          TextButton(
              onPressed: XfgNav.pop,
              style: xfgButtonStyle(Size(XfgSize().size200, XfgSize().size50),
                color: XfgColor.transparent,
                radius: XfgSize().size50,
                side: BorderSide(color: XfgColor.colorB8, width: XfgSize().size0_5)
              ),
              child: XfgText('返回首页', fontSize: XfgSize().text18, color: XfgColor.text2)
          ),
        ],
      ),
    );
  }

}
